﻿#region 头注释
/******************************************************************************
文件名称    :   ChemistryBlood.cs
创建日期    :   2011/5/11 22:15:45
功能描述    :   ChemistryBlood实体类
修改日志    :   
    2011-05-11 22:15  马利
*******************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Newtonsoft.Json;
using Dare.Utilities.Data;

namespace Stone.Components.Entities
{
    /// <summary>
    /// ChemistryBlood实体类
    /// </summary>
    public class ChemistryBlood : EntityBase<ChemistryBlood, long>
    {
        #region 构造函数

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ChemistryBlood()
            : base()
        {
            base.xmlSerializer = new DefaultXmlSerializer(this);
            base.jsonSerializer = new DefaultJsonSerializer(this);
        }

        public override void Reset()
        {
            wbc = null;
            lymL = null;
            m0L = null;
            granL = null;
            e0L = null;
            bas0L = null;
            lymP = null;
            m0P = null;
            e0P = null;
            bas0P = null;
            granP = null;
            rbc = null;
            hgb = null;
            hct = null;
            plt = null;
            comment = null;
            timeStamp = DateTime.MinValue;
        }

        public override ChemistryBlood CreateNew()
        {
            return new ChemistryBlood();
        }

        #endregion

        #region 属性

        /// <summary>
        /// 获取实体类型
        /// </summary>
        public override EntityType EntityType
        {
            get { return EntityType.ChemistryBlood; }
        }

        /// <summary>
        /// 获取或设置Wbc
        /// </summary>
        public decimal? Wbc
        {
            get { return wbc; }
            set
            {
                if (entityState == EntityState.Saved && wbc != value) entityState = EntityState.Changed;
                wbc = value;
            }
        }
        protected decimal? wbc;

        /// <summary>
        /// 获取或设置LymL
        /// </summary>
        public decimal? LymL
        {
            get { return lymL; }
            set
            {
                if (entityState == EntityState.Saved && lymL != value) entityState = EntityState.Changed;
                lymL = value;
            }
        }
        protected decimal? lymL;

        /// <summary>
        /// 获取或设置M0L
        /// </summary>
        public decimal? M0L
        {
            get { return m0L; }
            set
            {
                if (entityState == EntityState.Saved && m0L != value) entityState = EntityState.Changed;
                m0L = value;
            }
        }
        protected decimal? m0L;

        /// <summary>
        /// 获取或设置GranL
        /// </summary>
        public decimal? GranL
        {
            get { return granL; }
            set
            {
                if (entityState == EntityState.Saved && granL != value) entityState = EntityState.Changed;
                granL = value;
            }
        }
        protected decimal? granL;

        /// <summary>
        /// 获取或设置E0L
        /// </summary>
        public decimal? E0L
        {
            get { return e0L; }
            set
            {
                if (entityState == EntityState.Saved && e0L != value) entityState = EntityState.Changed;
                e0L = value;
            }
        }
        protected decimal? e0L;

        /// <summary>
        /// 获取或设置Bas0L
        /// </summary>
        public decimal? Bas0L
        {
            get { return bas0L; }
            set
            {
                if (entityState == EntityState.Saved && bas0L != value) entityState = EntityState.Changed;
                bas0L = value;
            }
        }
        protected decimal? bas0L;

        /// <summary>
        /// 获取或设置LymP
        /// </summary>
        public decimal? LymP
        {
            get { return lymP; }
            set
            {
                if (entityState == EntityState.Saved && lymP != value) entityState = EntityState.Changed;
                lymP = value;
            }
        }
        protected decimal? lymP;

        /// <summary>
        /// 获取或设置M0P
        /// </summary>
        public decimal? M0P
        {
            get { return m0P; }
            set
            {
                if (entityState == EntityState.Saved && m0P != value) entityState = EntityState.Changed;
                m0P = value;
            }
        }
        protected decimal? m0P;

        /// <summary>
        /// 获取或设置E0P
        /// </summary>
        public decimal? E0P
        {
            get { return e0P; }
            set
            {
                if (entityState == EntityState.Saved && e0P != value) entityState = EntityState.Changed;
                e0P = value;
            }
        }
        protected decimal? e0P;

        /// <summary>
        /// 获取或设置Bas0P
        /// </summary>
        public decimal? Bas0P
        {
            get { return bas0P; }
            set
            {
                if (entityState == EntityState.Saved && bas0P != value) entityState = EntityState.Changed;
                bas0P = value;
            }
        }
        protected decimal? bas0P;

        /// <summary>
        /// 获取或设置GranP
        /// </summary>
        public decimal? GranP
        {
            get { return granP; }
            set
            {
                if (entityState == EntityState.Saved && granP != value) entityState = EntityState.Changed;
                granP = value;
            }
        }
        protected decimal? granP;

        /// <summary>
        /// 获取或设置Rbc
        /// </summary>
        public decimal? Rbc
        {
            get { return rbc; }
            set
            {
                if (entityState == EntityState.Saved && rbc != value) entityState = EntityState.Changed;
                rbc = value;
            }
        }
        protected decimal? rbc;

        /// <summary>
        /// 获取或设置Hgb
        /// </summary>
        public decimal? Hgb
        {
            get { return hgb; }
            set
            {
                if (entityState == EntityState.Saved && hgb != value) entityState = EntityState.Changed;
                hgb = value;
            }
        }
        protected decimal? hgb;

        /// <summary>
        /// 获取或设置Hct
        /// </summary>
        public decimal? Hct
        {
            get { return hct; }
            set
            {
                if (entityState == EntityState.Saved && hct != value) entityState = EntityState.Changed;
                hct = value;
            }
        }
        protected decimal? hct;

        /// <summary>
        /// 获取或设置Plt
        /// </summary>
        public decimal? Plt
        {
            get { return plt; }
            set
            {
                if (entityState == EntityState.Saved && plt != value) entityState = EntityState.Changed;
                plt = value;
            }
        }
        protected decimal? plt;

        /// <summary>
        /// 获取或设置备注
        /// </summary>
        public string Comment
        {
            get { return comment; }
            set
            {
                if (entityState == EntityState.Saved && comment != value) entityState = EntityState.Changed;
                comment = value;
            }
        }
        protected string comment;

        /// <summary>
        /// 获取或设置更新时间戳
        /// </summary>
        public DateTime TimeStamp
        {
            get { return timeStamp; }
            set
            {
                if (entityState == EntityState.Saved && timeStamp != value) entityState = EntityState.Changed;
                timeStamp = value;
            }
        }
        protected DateTime timeStamp;

        #endregion

        #region 方法

        #endregion

        #region 实体复制相关方法

        /// <summary>
        /// 复制当前实体属性到指定实体上
        /// </summary>
        /// <param name="entity">要把属性复制到的实体</param>
        /// <returns>返回传入的实体</returns>
        public override ChemistryBlood CopyTo(ChemistryBlood entity)
        {
            if (base.CopyTo(entity) == null) return null;

            entity.wbc = this.wbc;
            entity.lymL = this.lymL;
            entity.m0L = this.m0L;
            entity.granL = this.granL;
            entity.e0L = this.e0L;
            entity.bas0L = this.bas0L;
            entity.lymP = this.lymP;
            entity.m0P = this.m0P;
            entity.e0P = this.e0P;
            entity.bas0P = this.bas0P;
            entity.granP = this.granP;
            entity.rbc = this.rbc;
            entity.hgb = this.hgb;
            entity.hct = this.hct;
            entity.plt = this.plt;
            entity.comment = this.comment;
            entity.timeStamp = this.timeStamp;

            return entity;
        }

        #endregion

        #region 默认XML序列器类

        public class DefaultXmlSerializer : XmlSerializerBase, IEntityXmlSerializer<ChemistryBlood>
        {
            ChemistryBlood entity;
            public DefaultXmlSerializer(ChemistryBlood entity)
                : base(entity.GetType().Name)
            {
                this.entity = entity;
            }

            public ChemistryBlood Entity
            {
                get { return entity; }
                set { entity = value; }
            }

            protected override void BeforeReadXml()
            {
                entity.Reset();
            }

            /// <summary>
            /// 读取XML属性
            /// </summary>
            /// <param name="name">属性名</param>
            /// <param name="value">属性值</param>
            /// <param name="reader">XML读取器</param>
            internal override void ReadXmlAttribute(string name, string value, XmlReader reader)
            {
                switch (name)
                {
                    case "id":
                        entity.id = XmlConvert.ToInt64(value);
                        break;
                    case "timeStamp":
                        entity.timeStamp = new DateTime(long.Parse(value));
                        break;
                    case "entityState":
                        entity.entityState = (EntityState)Enum.Parse(typeof(EntityState), value, true);
                        break;
                }
            }

            /// <summary>
            /// 读取XML子节点
            /// </summary>
            /// <param name="name">节点名</param>
            /// <param name="reader">XML读取器</param>
            internal override void ReadXmlChildElement(string name, XmlReader reader)
            {
                switch (name)
                {
                    case "Wbc":
                        entity.wbc = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "LymL":
                        entity.lymL = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "M0L":
                        entity.m0L = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "GranL":
                        entity.granL = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "E0L":
                        entity.e0L = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Bas0L":
                        entity.bas0L = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "LymP":
                        entity.lymP = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "M0P":
                        entity.m0P = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "E0P":
                        entity.e0P = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Bas0P":
                        entity.bas0P = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "GranP":
                        entity.granP = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Rbc":
                        entity.rbc = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Hgb":
                        entity.hgb = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Hct":
                        entity.hct = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Plt":
                        entity.plt = XmlConvert.ToDecimal(reader.ReadElementString());
                        break;
                    case "Comment":
                        entity.comment = reader.ReadElementString();
                        break;
                }
            }

            /// <summary>
            /// 写入XML属性
            /// </summary>
            /// <param name="writer">XML编写器</param>
            internal override void WriteXmlAttributes(XmlWriter writer)
            {
                writer.WriteAttributeString("id", XmlConvert.ToString(entity.Id));
                writer.WriteAttributeString("timeStamp", entity.TimeStamp.Ticks.ToString());
                writer.WriteAttributeString("entityState", entity.EntityState.ToString());
            }

            /// <summary>
            /// 写入XML子节点
            /// </summary>
            /// <param name="writer">XML编写器</param>
            internal override void WriteXmlChildElements(XmlWriter writer)
            {
                if (entity.Wbc != null) writer.WriteElementString("Wbc", XmlConvert.ToString(entity.Wbc.Value));
                if (entity.LymL != null) writer.WriteElementString("LymL", XmlConvert.ToString(entity.LymL.Value));
                if (entity.M0L != null) writer.WriteElementString("M0L", XmlConvert.ToString(entity.M0L.Value));
                if (entity.GranL != null) writer.WriteElementString("GranL", XmlConvert.ToString(entity.GranL.Value));
                if (entity.E0L != null) writer.WriteElementString("E0L", XmlConvert.ToString(entity.E0L.Value));
                if (entity.Bas0L != null) writer.WriteElementString("Bas0L", XmlConvert.ToString(entity.Bas0L.Value));
                if (entity.LymP != null) writer.WriteElementString("LymP", XmlConvert.ToString(entity.LymP.Value));
                if (entity.M0P != null) writer.WriteElementString("M0P", XmlConvert.ToString(entity.M0P.Value));
                if (entity.E0P != null) writer.WriteElementString("E0P", XmlConvert.ToString(entity.E0P.Value));
                if (entity.Bas0P != null) writer.WriteElementString("Bas0P", XmlConvert.ToString(entity.Bas0P.Value));
                if (entity.GranP != null) writer.WriteElementString("GranP", XmlConvert.ToString(entity.GranP.Value));
                if (entity.Rbc != null) writer.WriteElementString("Rbc", XmlConvert.ToString(entity.Rbc.Value));
                if (entity.Hgb != null) writer.WriteElementString("Hgb", XmlConvert.ToString(entity.Hgb.Value));
                if (entity.Hct != null) writer.WriteElementString("Hct", XmlConvert.ToString(entity.Hct.Value));
                if (entity.Plt != null) writer.WriteElementString("Plt", XmlConvert.ToString(entity.Plt.Value));
                if (entity.Comment != null) writer.WriteElementString("Comment", entity.Comment);
            }
        }

        #endregion

        #region 默认Json序列化器类

        public class DefaultJsonSerializer : JsonSerializerBase, IEntityJsonSerializer<ChemistryBlood>
        {
            ChemistryBlood entity;
            public DefaultJsonSerializer(ChemistryBlood entity)
                : base()
            {
                this.entity = entity;
            }

            public ChemistryBlood Entity
            {
                get { return entity; }
                set { entity = value; }
            }

            /// <summary>
            /// 读取JSON属性
            /// </summary>
            /// <param name="propName">属性名称</param>
            /// <param name="propValue">属性值</param>
            /// <param name="reader">JSON读取器</param>
            protected override void ReadJsonProperty(string propName, object propValue, JsonReader reader)
            {
                switch (propName)
                {
                    case "id":
                        entity.id = DbConvert.ToNullableInt64(propValue) ?? entity.id;
                        break;
                    case "wbc":
                        entity.wbc = DbConvert.ToNullableDecimal(propValue) ?? entity.wbc;
                        break;
                    case "lymL":
                        entity.lymL = DbConvert.ToNullableDecimal(propValue) ?? entity.lymL;
                        break;
                    case "m0L":
                        entity.m0L = DbConvert.ToNullableDecimal(propValue) ?? entity.m0L;
                        break;
                    case "granL":
                        entity.granL = DbConvert.ToNullableDecimal(propValue) ?? entity.granL;
                        break;
                    case "e0L":
                        entity.e0L = DbConvert.ToNullableDecimal(propValue) ?? entity.e0L;
                        break;
                    case "bas0L":
                        entity.bas0L = DbConvert.ToNullableDecimal(propValue) ?? entity.bas0L;
                        break;
                    case "lymP":
                        entity.lymP = DbConvert.ToNullableDecimal(propValue) ?? entity.lymP;
                        break;
                    case "m0P":
                        entity.m0P = DbConvert.ToNullableDecimal(propValue) ?? entity.m0P;
                        break;
                    case "e0P":
                        entity.e0P = DbConvert.ToNullableDecimal(propValue) ?? entity.e0P;
                        break;
                    case "bas0P":
                        entity.bas0P = DbConvert.ToNullableDecimal(propValue) ?? entity.bas0P;
                        break;
                    case "granP":
                        entity.granP = DbConvert.ToNullableDecimal(propValue) ?? entity.granP;
                        break;
                    case "rbc":
                        entity.rbc = DbConvert.ToNullableDecimal(propValue) ?? entity.rbc;
                        break;
                    case "hgb":
                        entity.hgb = DbConvert.ToNullableDecimal(propValue) ?? entity.hgb;
                        break;
                    case "hct":
                        entity.hct = DbConvert.ToNullableDecimal(propValue) ?? entity.hct;
                        break;
                    case "plt":
                        entity.plt = DbConvert.ToNullableDecimal(propValue) ?? entity.plt;
                        break;
                    case "comment":
                        entity.comment = Convert.ToString(propValue) ?? entity.comment;
                        break;
                    case "timeStamp":
                        entity.timeStamp = new DateTime(DbConvert.ToNullableInt64(propValue) ?? 0);
                        break;
                }
            }

            /// <summary>
            /// 写入JSON属性
            /// </summary>
            /// <param name="writer">JSON编写器</param>
            protected override void WriteJsonProperties(JsonWriter writer)
            {

                //Id
                writer.WritePropertyName("id");
                writer.WriteValue(entity.Id);

                //Wbc
                writer.WritePropertyName("wbc");
                if (entity.Wbc == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Wbc.Value);
                }

                //LymL
                writer.WritePropertyName("lymL");
                if (entity.LymL == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.LymL.Value);
                }

                //M0L
                writer.WritePropertyName("m0L");
                if (entity.M0L == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.M0L.Value);
                }

                //GranL
                writer.WritePropertyName("granL");
                if (entity.GranL == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.GranL.Value);
                }

                //E0L
                writer.WritePropertyName("e0L");
                if (entity.E0L == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.E0L.Value);
                }

                //Bas0L
                writer.WritePropertyName("bas0L");
                if (entity.Bas0L == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Bas0L.Value);
                }

                //LymP
                writer.WritePropertyName("lymP");
                if (entity.LymP == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.LymP.Value);
                }

                //M0P
                writer.WritePropertyName("m0P");
                if (entity.M0P == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.M0P.Value);
                }

                //E0P
                writer.WritePropertyName("e0P");
                if (entity.E0P == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.E0P.Value);
                }

                //Bas0P
                writer.WritePropertyName("bas0P");
                if (entity.Bas0P == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Bas0P.Value);
                }

                //GranP
                writer.WritePropertyName("granP");
                if (entity.GranP == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.GranP.Value);
                }

                //Rbc
                writer.WritePropertyName("rbc");
                if (entity.Rbc == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Rbc.Value);
                }

                //Hgb
                writer.WritePropertyName("hgb");
                if (entity.Hgb == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Hgb.Value);
                }

                //Hct
                writer.WritePropertyName("hct");
                if (entity.Hct == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Hct.Value);
                }

                //Plt
                writer.WritePropertyName("plt");
                if (entity.Plt == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Plt.Value);
                }

                //备注
                writer.WritePropertyName("comment");
                if (entity.Comment == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteValue(entity.Comment);
                }

                //更新时间戳
                writer.WritePropertyName("timeStamp");
                writer.WriteValue(entity.TimeStamp.Ticks);
            }
        }


        #endregion
    }
}